<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
<title>国省自检--${fns:getConfig('productName')}</title>
<%@ include file="/common/treeview.jsp"%>
<script type="text/javascript">
$(document).ready(function(){
	wordCount();  //统计textarea中的字数
	$("#inputForm").validate({
		rules: {
			projectName: {
				remote:"${ctx}/countryCheck/check.do?oldName=" + encodeURIComponent("${checkProject.projectName}")
			}
		},
		messages: {
			projectName: {remote: "该项目名称已存在"}
		},
		submitHandler:function(form){
			var ids = [], nodes = tree.getCheckedNodes(true);
			for(var i=0; i<nodes.length; i++) {
				ids.push(nodes[i].id);
			}
			$("#menuIds").val(ids);
			form.submit();
		},
		errorContainer: "#messageBox",
		errorPlacement: function(error, element) {
			$("#messageBox").text("输入有误，请先更正。");
			if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
				error.appendTo(element.parent().parent());
			} else {
				error.insertAfter(element);
			}
		}
	});
	var setting={
			check:{enable:true,nocheckInherit:true},
			view:{selectedMulti:false},
			data:{simpleData:{enable:true}},
			callback:{
				beforeClick:function(id, node){
					tree.checkNode(node, !node.checked, true, true);
					return false;
					}
			}
		};
	
	//公路监管菜单
	var zNodes=[
			<c:forEach items="${menuList}" var="menu">{
				id:"${menu.id}", 
				pId:"${not empty menu.parent.id?menu.parent.id:0}", 
				name:"${not empty menu.parent.id?menu.name:'权限列表'}"
				},
            </c:forEach>];
	console.log(zNodes);
	// 初始化树结构
	var tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
	// 默认选择节点
	var ids = "${checkProject.menuIds}".split(",");
	for(var i=0; i<ids.length; i++){
		var node = tree.getNodeByParam("id", ids[i]);
		try{
			tree.checkNode(node, true, false);
			if(i==1){ //指定展开第一级的节点
				 tree.selectNode(node);//选择点  
			     tree.setting.callback.onClick(null, tree.setting.treeId, node);//调用事件  
			}
		}catch(e){}
	}
	// 默认展开全部节点
// 	tree.expandAll(false);
});
</script>
</head>
<body>
	<ul class="nav nav-tabs" style="margin:0 4px 15px 4px;">
		<li><a href="${ctx}/province/showList.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}">
			<i class="icon icon-list"></i>&nbsp;<span>省检列表</span></a></li>
			<sec:authorize ifAnyGranted="ROLE_gsj_editor">
		<li class="active"><a href="${ctx}/province/input.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}">
		     <i class="icon icon-edit"></i>&nbsp;<span>${not empty checkProject.id?'修改':'新增'}</span></a></li>
		     </sec:authorize>
	</ul>
	<form id="inputForm" action="${ctx}/province/save.do?left=${fns:encodeParam(left)}&parentId=${fns:encodeParam(parentId)}"
		method="post" class="form-horizontal propertyHeight" style="width:auto;overflow:auto;">
		<input type="hidden" name="id" value="${checkProject.id}" />
		<input type="hidden" name="token" value="${token}">
		<input type="hidden" name="countryOrProvince" value="1">
		<input type="hidden" name="status" value="0">
		<div class="control-group">
			<label class=" control-label">项目名称<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input class="required" id="projectName" name="projectName"
					type="text" value="${checkProject.projectName}">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">开始时间<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input  id="startTime" name="startTime" value="${checkProject.startTime}" class="required"
										onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy',maxDate:'#F{$dp.$D(\'endTime\',{y:-1})}', minDate:'#F{$dp.$D(\'endTime\',{y:-1})}'})" class="Wdate" type="text">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">结束时间<font style="color:red;">*</font>:</label>
			<div class="controls">
				<input  id="endTime" name="endTime" value="${checkProject.endTime}" class="required"
										onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy', maxDate:'#F{$dp.$D(\'startTime\',{y:1})}', minDate:'#F{$dp.$D(\'startTime\',{y:+1})}'})" class="Wdate" type="text">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">备注:</label>
			<div class="controls">
				<input class="" id="remark" name="remark"
					type="text" value="${checkProject.remark}">
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">项目概述:</label>
			<div class="controls">
				<div class="wordCount wyInline" id="wordCount">
					<textarea placeholder="文件内容描述" rows='3' id="content"
						name="content">${checkProject.content}</textarea>
					<span class="wordwrap"><var class="word">2000</var>/2000</span>
				</div>
			</div>
		</div>
		<div class="control-group">
			<label class=" control-label">检查内容:</label>
			<div class="controls">
				<div id="menuTree" class="ztree"
					style="margin-top: 3px; float: left;"></div>
				<input type="hidden" id="menuIds" name="menuIds" value="${checkProject.menuIds}" />
			</div>
		</div>

		<div class="form-actions">
		<sec:authorize ifAnyGranted="ROLE_sys_role_edit"></sec:authorize>
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />
					&nbsp; <input id="btnCancel" class="btn"
					type="button" value="返 回" onclick="toBack()" />
		</div>
	</form>
	<script>$(".span10").css({"width":($(window).width()-237)+"px","margin":"0 0 0 2px"});</script>
</body>
</html>